﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TT.Runtime.Type
{
    public static class Primitive
    {
        public readonly static IType[] All;
        static Primitive()
        {
            Void = new Void();
            DataType = new DataType(); //一切结构体的基类型
            Boolean = new Boolean();
            Int8 = new Int8();
            Int16 = new Int16();
            Int32 = new Int32();
            Int64 = new Int64();
            UInt8 = new UInt8();
            UInt16 = new UInt16();
            UInt32 = new UInt32();
            UInt64 = new UInt64();
            Float32 = new Float32();
            Float64 = new Float64();
            All = new IType[] {
                Void, DataType, Boolean ,
                Int8 , Int16 , Int32 , Int64 , UInt8 , UInt16 , UInt32, UInt64,
                Float32,Float64
            };
        }
        public static IType GetArrayType(IType Element)
        {
            return new PrimitiveArrayType(Element);
        }
        public readonly static IType Void;
        public readonly static IType DataType;
        public readonly static IType Boolean;
        public readonly static IType Int8;
        public readonly static IType Int16;
        public readonly static IType Int32;
        public readonly static IType Int64;
        public readonly static IType UInt8;
        public readonly static IType UInt16;
        public readonly static IType UInt32;
        public readonly static IType UInt64;
        public readonly static IType Float32;
        public readonly static IType Float64;
    }
    public interface IArrayType : IType
    {
        IType elementType
        {
            get;
        }
    }
    public class PrimitiveArrayType : PrimitiveType, IArrayType
    {
        public PrimitiveArrayType(IType element)
        {
            this.elementType = element;
        }
        public override string name => "PrimitiveArray";
        public IType elementType
        {
            get;
            private set;
        }
    }
    public abstract class PrimitiveType : IType
    {
        public abstract string name
        {
            get;
        }
        public string libname => "";

        public bool isClass => false;

        public bool isInterface => false;
        public bool isExport => true;

        public IType basetype => Primitive.DataType;

        public IType[] _interface => null;

        public IField[] fields => null;

        public IMethod[] Methods => null;
    }
    public class Boolean : PrimitiveType
    {
        public override string name => "void";

    }
    public class Int8 : PrimitiveType
    {
        public override string name => "int8";
    }
    public class Int16 : PrimitiveType
    {
        public override string name => "int16";
    }

    public class Int32 : PrimitiveType
    {
        public override string name => "int32";
    }

    public class Int64 : PrimitiveType
    {
        public override string name => "int64";
    }

    public class UInt8 : PrimitiveType
    {
        public override string name => "uint8";
    }
    public class UInt16 : PrimitiveType
    {
        public override string name => "uint16";
    }

    public class UInt32 : PrimitiveType
    {
        public override string name => "uint32";
    }

    public class UInt64 : PrimitiveType
    {
        public override string name => "uint64";
    }
    public class Float32 : PrimitiveType
    {
        public override string name => "float32";
    }

    public class Float64 : PrimitiveType
    {
        public override string name => "float64";
    }
    //void 是一个特殊的类型，他所有的属性没有意义
    public class Void : IType
    {
        public string name => "void";
        public string libname => "";
        public bool isClass => false;

        public bool isExport => false;
        public bool isInterface => false;
        public IType basetype => null;

        public IType[] _interface => null;

        public IField[] fields => null;

        public IMethod[] Methods => null;
    }
    //Null 不是一个type，Object type可以表达NULL
    //public class Null:Object
    //{
    //    public override string name => "NULL";
    //}
    //所有内置类型的基类,但不是公开的类型，用户不能使用
    public class DataType : IType
    {
        public string name => "data";
        public string libname => "";

        public bool isClass => false;

        public bool isExport => false;
        public bool isInterface => false;
        public IType basetype => null;

        public IType[] _interface => null;

        public IField[] fields => null;

        public IMethod[] Methods => null;
    }


}
